package com.zhangmengyuan.medical.controller;

import com.zhangmengyuan.medical.entity.ClassEntity;
import com.zhangmengyuan.medical.service.ClassEntityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("classEntity")
public class ClassEntityController {
    @Autowired
    private ClassEntityService classEntitysService;
    public String save(ClassEntity classEntity, Model model){
        this.classEntitysService.save(classEntity);
        return "redirect:/class/all";
    }

    public String update(ClassEntity classEntity, @PathVariable("classId") Integer classId, Model model){
        classEntity.setClassId(classId);
        this.classEntitysService.save(classEntity);
        return "redirect:/goods/all";
    }
    public String getClassEntity(Model model){
        List<ClassEntity> classEntityList=this.classEntitysService.getAll();
        model.addAttribute("classEntityList",classEntityList);
        return "modifyclass";
    }
    public String getClassEntityById(ClassEntity classEntity, @PathVariable("classId")Integer classId,Model model){
        classEntity=this.classEntitysService.getById(classId);
        model.addAttribute("classEntity",classEntity);
        return "modifyclass";

    }
    public String toDetil(Model model) {
        return "modifyclass";
    }
}
